<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('入库统计')"/>
    <style>
        [v-cloak] {
            display: none;
        }
        .el-date-editor.el-input, .el-date-editor.el-input__inner {
            width: 200px!important;
        }
        .el-input__icon {
            line-height: 0!important;
        }
        .tag {
            display: inline-block;
            padding: 0 5px;
            line-height: 22px;
            color: #FFFFFF;
            border-radius: 3px;
        }
    </style>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            库存地点：
                            <select name="wareId" v-model="wareId">
                                <option value="">全部</option>
                                <option v-for="(item, index) in wares" :key="index" :value="item.wareId" v-cloak>{{item.wareName}}</option>
                            </select>
                        </li>
                        <li>
                            货区：
                            <select name="areaId">
                                <option value="">全部</option>
                                <option v-for="(item, index) in areas" :key="index" :value="item.areaId" v-cloak>{{item.areaName}}</option>
                            </select>
                        </li>
                        <li>
                            托盘号：<input type="text" id="carrierId" name="carrierId"/>
                        </li>
                        <li>
                            批次号：<input type="text" id="materialBatchId" name="materialBatchId"/>
                        </li>
                        <li>
                            物料品质：<input type="text" id="materialQuality" name="materialQuality"/>
                        </li>
                        <li>
                            <label>入库时间：</label>
                            <el-date-picker
                                name="startTime"
                                v-model="timeA"
                                value-format="yyyy-MM-dd HH:mm:ss"
                                type="datetime"
                                @change="compareAB"
                                placeholder="开始时间">
                            </el-date-picker>
                            <span>-</span>
                            <el-date-picker
                                name="endTime"
                                v-model="timeB"
                                value-format="yyyy-MM-dd HH:mm:ss"
                                type="datetime"
                                @change="compareAB"
                                placeholder="结束时间">
                            </el-date-picker>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()" @click="resetTime()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>
        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="in:MaterialInfo:export">
                <i class="fa fa-download"></i> 导出全部
            </a>
            <a class="btn btn-info" @click="partExcel()" shiro:hasPermission="in:MaterialInfo:partExcel">
                <i class="fa fa-download"></i> 部分导出
            </a>
            <a class="btn btn-primary" onclick="$.table.print()">
                <i class="fa fa-plus"></i> 打印
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table" data-mobile-responsive="true" style="white-space: nowrap"></table>
        </div>
    </div>
</div>

<div th:include="include :: footer"></div>
<script th:src="@{/wms/js/common_fun.js}"></script>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('in:MaterialInfo:edit')}]];
    var prefix = ctx + "in/boxItem";

    var app = new Vue({
        el: '.container-div',
        data: {
            timeA: '',
            timeB: '',
            areas: [],
            wareId:'',
        },
        methods: {
            //获取货区列表
            getAreas: function(){
                var that = this;
                $.ajax({
                    cache: true,
                    type: "POST",
                    url: "/system/areaInfo/list",
                    data: {
                        wareId: this.wareId,
                    },
                    async: false,
                    error: function(request){
                        $.modal.alertError("系统错误");
                    },
                    success: function(data){
                        that.areas = data.rows;
                    }
                });
            },
            //时间对比
            compareAB: function(){
                if(this.timeA != '' && this.timeA != null){
                    if(this.timeB != '' && this.timeB != null){
                        var a = new Date(this.timeA);
                        var b = new Date(this.timeB);
                        if(a > b){
                            $.modal.alertError("结束时间需大于开始时间，请重新选择！！");
                            this.timeA = '';
                            this.timeB = '';
                        }
                    }else{
                        this.timeB = '';
                    }
                }else{
                    this.timeA = '';
                    if(this.timeB == null){
                        this.timeB = '';
                    }
                }
            },
            //清空时间
            resetTime(){
                this.timeA = '';
                this.timeB = '';
            },
            //部分导出
            partExcel(){
                var rows = $.common.isEmpty($.table._option.uniqueId) ? $.table.selectColumns('carrierId') : $.table.selectColumns($.table._option.uniqueId);
                if(rows.length == 0){
                    $.modal.alertWarning("请至少选择一条记录");
                    return;
                }else{
                    $.modal.confirm("确认要导出选中的" + rows.length + "条数据吗?", function(){
                        var url = prefix + "/partExcel";
                        var data = {"ids": rows.join()};
                        $.post(url, data, function(result){
                            if(result.code == web_status.SUCCESS){
                                window.location.href = ctx + "common/download?fileName=" + encodeURI(result.msg) + "&delete=" + true;
                            }else if(result.code == web_status.WARNING){
                                $.modal.alertWarning(result.msg);
                            }else{
                                $.modal.alertError(result.msg);
                            }
                            $.modal.closeLoading();
                        });
                    });
                }
            }
        },
        watch: {
            wareId: function f( newVal ,oldVal){
               this.getAreas();
            }
        },
        created(){
            this.getAreas();
            getWares();
        }
    })

    $(function() {
        var options = {
            url: prefix + "/selectWholeTorrInfo",
            exportUrl: prefix + "/export",
            // updateUrl: "/in/MaterialInfo/edit/{id}",
            updateUrl: "/in/boxItem/edit/{id}",
            detailUrl: "/in/MaterialInfo/detail",
            modalName: "单晶托入库",
            columns: [
                {
                    checkbox: true
                },
                {
                    field: 'id',
                    title: '序号',
                    align: 'center',
                    visible: false
                },
                {
                    field: 'carrierId',
                    title: '托盘号',
                    align: 'center'
                },
                {
                    field: 'materialBatchId',
                    title: '批次号',
                    align: 'center'
                },
                {
                    field: 'wareCode',
                    title: '库存地点',
                    align: 'center'
                },
                {
                    field: 'areaName',
                    title: '货区',
                    align: 'center'
                },
                {
                    title: '物料名称',
                    align: 'center',
                    formatter: function(value, row, index){
                        return '钢卷';
                    }
                },
                {
                    field: 'materialQuality',
                    title: '物料品质',
                    align: 'center'
                },
                {
                    field: 'inTime',
                    title: '入库时间',
                    align: 'center',
                    formatter: function(value, item, index){
                        if(value == null){
                            return '';
                        }else{
                            return value.slice(0, 19);
                        }
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    events: {
                        'click .detail': function(e, value, rowData, index){
                            var id = rowData.carrierId;
                            var _url = $.table._option.detailUrl;
                            localStorage.setItem(_url, id.toString());
                            localStorage.setItem('inMaterialInfoEditFlag', 'close');
                            open("单晶托详情", _url, '1600', '720', null);
                        },
                        'click .detailEdit': function(e, value, rowData, index){
                            var id = rowData.carrierId;
                            var _url = $.table._option.detailUrl;
                            localStorage.setItem(_url, id.toString());
                            localStorage.setItem('inMaterialInfoEditFlag', 'open');
                            open("单晶托详情", _url, '1600', '720', null);
                        }
                    },
                    formatter: function(value, row, index){
                        var actions = [];
                        // actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="#" onclick="$.operate.edit(\'' + row.carrierId + '\')"><i class="fa fa-edit"></i> 修改</a> ');
                        // actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="#" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i> 修改</a> ');
                        actions.push("<span class='detailEdit tag' style='background-color: #1ab394;cursor: pointer'><i class='fa fa-credit-card'></i> 明细修改</span> ");
                        actions.push("<span class='detail tag' style='background-color: #3097b5;cursor: pointer'><i class='fa fa-hand-pointer-o'></i> 查看</span>");
                        return actions.join('');
                    }
                }
            ]
        };
        $.table.init(options);
    });

    function open(title, url, width, height, callback){
        if(navigator.userAgent.match(/(iPhone|iPod|Android|ios)/i)){
            width = 'auto';
            height = 'auto';
        }
        if($.common.isEmpty(title)){
            title = false;
        }
        if($.common.isEmpty(url)){
            url = "/404.html";
        }
        if($.common.isEmpty(width)){
            width = 800;
        }
        if($.common.isEmpty(height)){
            height = ($(window).height() - 250);
        }
        if($.common.isEmpty(callback)){
            callback = function(index, layero){
                var iframeWin = layero.find('iframe')[0];
                iframeWin.contentWindow.submitHandler();
            }
        }
        layer.open({
            type: 2,
            area: [width + 'px', height + 'px'],
            fix: false,
            maxmin: true,
            shade: 0.3,
            title: title,
            content: url,
            btn: ['关闭'],
            shadeClose: true,
            cancel: function(index){
                return true;
            }
        });
    }
</script>
</body>
</html>
